<!--
~ Copyright 2019-present Open Networking Foundation
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~     http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<!-- Port partial HTML -->
<div id="ov-roadm-port">
    <!--<onos-loading [theme]="'light'" [running]="loadingIconShown"></onos-loading>-->
    <div class="tabular-header">
        <h2>
            Ports for Optical Device {{devId}} ({{tableData.length}} Total)
        </h2>

        <div class="ctrl-btns">
            <div class="refresh" (click)="toggleRefresh()">
                <!-- See icon.theme.css for the defintions of the classes active and refresh-->
                <onos-icon classes="{{ autoRefresh?'active refresh':'refresh' }}" iconId="refresh" iconSize="42" toolTip="{{ autoRefreshTip }}"></onos-icon>
            </div>

            <div class="separator"></div>

            <div routerLink="/roadm-gui" [queryParams]="{ devId: devId }" routerLinkActive="active">
                <onos-icon classes="{{ devId ? 'active-rect':undefined }}" iconId="deviceTable" iconSize="42" toolTip="{{deviceTip}}"></onos-icon>
            </div>

            <!--<div routerLink="/flow" [queryParams]="{ devId: devId }" routerLinkActive="active">-->
                <!--<onos-icon classes="{{ devId ? 'active-rect' :undefined}}" iconId="flowTable" iconSize="42" toolTip="{{ flowTip }}"></onos-icon>-->
            <!--</div>-->

            <div>
                <onos-icon classes="{{ devId ? 'current-view' :undefined}}" iconId="portTable" iconSize="42"></onos-icon>
            </div>

        </div>

        <div class="search">
            <input id="searchinput" [(ngModel)]="tableDataFilter.queryStr" type="search" #search placeholder="Search" />
            <select [(ngModel)]="tableDataFilter.queryBy">
                <option value="" disabled>Search By</option>
                <option value="$">All Fields</option>
                <option value="id">Port ID</option>
                <option value="name">Pkts Received</option>
                <option value="type">Pkts Sent</option>
                <option value="enabled">Bytes Received</option>
                <option value="grid">Bytes Sent</option>
                <option value="hasTargetPower">Pkts RX Dropped</option>
            </select>
        </div>
    </div>

    <div class="summary-list" onosTableResize>
        <div class="table-header">
            <table>
                <tr>
                    <td colId="id">PORT ID</td>
                    <td colId="reversePort">REVERSE PORT</td>
                    <td colId="name">NAME</td>
                    <td colId="type">TYPE</td>
                    <td colId="enabled">ENABLED</td>
                    <td colId="minFreq">MIN FREQ (THz)</td>
                    <td colId="maxFreq">MAX FREQ (THz)</td>
                    <td colId="grid">GRID (GHz)</td>
                    <td colId="currentFreq">CURRENT FREQ (THz)</td>
                    <td colId="modulation">MODULATION</td>
                    <td colId="powerRange">POWER RANGE (dBm)</td>
                    <td colId="currentPower">CURRENT OUTPUT POWER (dBm)</td>
                    <td colId="currentInputPower">CURRENT INPUT POWER (dBm)</td>
                    <td colId="targetPower">TARGET OUTPUT POWER (dBm)</td>
                    <td colId="hasTargetPower">HAS TARGET POWER</td>
                    <td colId="PRE_FEC_BER">PRE FEC BER</td>
                    <td colId="POST_FEC_BER">POST FEC BER</td>
                    <td colId="serviceState">SERVICE STATE</td>
                </tr>
            </table>
        </div>

        <div class="table-body">
            <table>
                <tr class="table-body" *ngIf="tableData.length === 0" class="no-data">
                    <td colspan="9">{{annots.noRowsMsg}}</td>
                </tr>

                <tr *ngFor="let port of tableData | filter : tableDataFilter" (click)="selectCallback($event, port)" [ngClass]="{selected: port.id === selId, 'data-change': isChanged(port.id)}">
                    <td>{{port.id}}</td>
                    <td [ngClass]="(isDelta() ? 'delta' : '')">{{port.reversePort}}</td>
                    <td [ngClass]="(isDelta() ? 'delta' : '')">{{port.name}}</td>
                    <td [ngClass]="(isDelta() ? 'delta' : '')">{{port.type}}</td>
                    <td [ngClass]="(isDelta() ? 'delta' : '')">{{port.enabled}}</td>
                    <td [ngClass]="(isDelta() ? 'delta' : '')">{{port.type=='OCH' || port.type=='OMS'?port.minFreq:""}}</td>
                    <td [ngClass]="(isDelta() ? 'delta' : '')">{{port.type=='OCH' || port.type=='OMS'?port.maxFreq:""}}</td>
                    <td [ngClass]="(isDelta() ? 'delta' : '')">{{port.type=='OCH' || port.type=='OMS'?port.grid:""}}</td>
                    <td [ngClass]="(isDelta() ? 'delta' : '')">
                        <form [formGroup]="freqForm" (ngSubmit)="submitFrequency(devId, port.id)" *ngIf="port.type=='OCH'">
                            <input type="text" style="width:50px" value="{{port.type=='OCH'?port.currFreq:''}}" formControlName="newFreq" required>
                            <button type="submit">Submit</button>
                        </form>
                    </td>
                    <td [ngClass]="(isDelta() ? 'delta' : '')">
                        <form [formGroup]="modulationForm" (ngSubmit)="submitModulation(devId, port.id)" *ngIf="port.type=='OCH'">
                            <select [(ngModel)]="port.modulation" formControlName="newModulation">
                                <option value="dp_qpsk">qpsk</option>
                                <option value="dp_16qam">16qam</option>
                            </select>
                            <button type="submit">Submit</button>
                        </form>
                    </td>
                    <td [ngClass]="(isDelta() ? 'delta' : '')">{{port.powerRange}}</td>
                    <td [ngClass]="(isDelta() ? 'delta' : '')">{{convertNumber(port.currentPower) | number: '1.2-2'}}</td>
                    <td [ngClass]="(isDelta() ? 'delta' : '')">{{convertNumber(port.currentInputPower) | number: '1.2-2'}}</td>
                    <td [ngClass]="(isDelta() ? 'delta' : '')">
                        <form [formGroup]="powerForm" (ngSubmit)="submitPower(devId, port.id)" *ngIf="port.type=='OCH' || port.type=='OMS'">
                            <input type="number" step="any" style="width:50px" value="{{convertNumber(port.targetPower) | number: '1.2-2'}}" formControlName="newPower" required>
                            <button type="submit">Submit</button>
                        </form>
                    </td>
                    <td [ngClass]="(isDelta() ? 'delta' : '')">{{port.hasTargetPower}}</td>
                    <td [ngClass]="(isDelta() ? 'delta' : '')">{{convertNumber(port.preFecBitErrorRate)}}</td>
                    <td [ngClass]="(isDelta() ? 'delta' : '')">{{convertNumber(port.postFecBitErrorRate)}}</td>
                    <td [ngClass]="(isDelta() ? 'delta' : '')">{{port.serviceState}}</td>
                </tr>
            </table>
        </div>
    </div>
</div>
